const {ccclass, property} = cc._decorator;

/**
 * 常驻节点，主要功能为切换场景、传递分数等数据
 */

@ccclass
export default class MainControl extends cc.Component {


    onload() {


        cc.director.preloadScene("flappyBird", function () {
            cc.log("Next scene preloaded");
        });
        cc.director.preloadScene("gameOver", function () {
            cc.log("Next scene preloaded");
        });
    }

    start() {
        console.log(cc.director.getScene())
    }


    beginGame() {
        cc.director.loadScene('flappyBird');
    }

    gameOver(score: number) {
        cc.sys.localStorage.setItem('score', score);
        // 判断是否历史最高分
        let best = cc.sys.localStorage.getItem('best') || 0;
        console.log(best)
        if (score > best) {
            cc.sys.localStorage.setItem('best', score);
        }
        cc.director.loadScene("gameOver");
    }
}
